<template>
  <div class="app-container">
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="150px"  style="width: 100%; padding: 0 30px;">

        <el-row :gutter="20">
                      <el-col :span="12">
                <el-form-item label="tmptUserType" prop="tmptUserType">
                  <el-input v-model="temp.tmptUserType" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="tmptAuthPosition" prop="tmptAuthPosition">
                  <el-input v-model="temp.tmptAuthPosition" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="tmptAuthDeptPostId" prop="tmptAuthDeptPostId">
                  <el-input v-model="temp.tmptAuthDeptPostId" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="ctcRegionId" prop="ctcRegionId">
                  <el-input v-model="temp.ctcRegionId" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="clientId" prop="clientId">
                  <el-input v-model="temp.clientId" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="positionShow" prop="positionShow">
                  <el-input v-model="temp.positionShow" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="contactType" prop="contactType">
                  <el-input v-model="temp.contactType" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="policceNumber" prop="policceNumber">
                  <el-input v-model="temp.policceNumber" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="headPic" prop="headPic">
                  <el-input v-model="temp.headPic" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="lawEqpNo" prop="lawEqpNo">
                  <el-input v-model="temp.lawEqpNo" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="loginname" prop="loginname">
                  <el-input v-model="temp.loginname" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="name" prop="name">
                  <el-input v-model="temp.name" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="idcardno" prop="idcardno">
                  <el-input v-model="temp.idcardno" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="email" prop="email">
                  <el-input v-model="temp.email" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="jobNumber" prop="jobNumber">
                  <el-input v-model="temp.jobNumber" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="phone" prop="phone">
                  <el-input v-model="temp.phone" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="telephone" prop="telephone">
                  <el-input v-model="temp.telephone" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="sex" prop="sex">
                  <el-input v-model="temp.sex" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="tmptAuthDeptId" prop="tmptAuthDeptId">
                  <el-input v-model="temp.tmptAuthDeptId" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="删除标志" prop="deleteflag">
                  <select-option
                      v-model="temp.deleteflag"
                      :clearable=false
                      prop-name="Deleteflag"
                      :prop-ds-type=1
                      prop-url="/citymh/enum/getData4AddBy"
                  />
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
  </div>
</template>

<script>
import {createApi, updateApi, fetchList} from './api'
// 导入多选项组件
import SelectOption from '@/views/coding/components/SelectOption'

export default {
    name: 'TmptAuthUser-FormDetail',

    components: { SelectOption },

    props: {
        isModule: {
            type: Boolean,
            default: false
        },
        row: {}
    },

    data() {
        return {
            rules: {
                tmptUserType: [{ required: true, message: 'required', trigger: 'blur' }],
                tmptAuthPosition: [{ required: true, message: 'required', trigger: 'blur' }],
                tmptAuthDeptPostId: [{ required: true, message: 'required', trigger: 'blur' }],
                ctcRegionId: [{ required: true, message: 'required', trigger: 'blur' }],
                clientId: [{ required: true, message: 'required', trigger: 'blur' }],
                positionShow: [{ required: true, message: 'required', trigger: 'blur' }],
                contactType: [{ required: true, message: 'required', trigger: 'blur' }],
                policceNumber: [{ required: true, message: 'required', trigger: 'blur' }],
                headPic: [{ required: true, message: 'required', trigger: 'blur' }],
                lawEqpNo: [{ required: true, message: 'required', trigger: 'blur' }],
                loginname: [{ required: true, message: 'required', trigger: 'blur' }],
                name: [{ required: true, message: 'required', trigger: 'blur' }],
                idcardno: [{ required: true, message: 'required', trigger: 'blur' }],
                email: [{ required: true, message: 'required', trigger: 'blur' }],
                jobNumber: [{ required: true, message: 'required', trigger: 'blur' }],
                phone: [{ required: true, message: 'required', trigger: 'blur' }],
                telephone: [{ required: true, message: 'required', trigger: 'blur' }],
                sex: [{ required: true, message: 'required', trigger: 'blur' }],
                tmptAuthDeptId: [{ required: true, message: 'required', trigger: 'blur' }],
                deleteflag: [{ required: true, message: 'required', trigger: 'blur' }],
            },
            temp: {
            }
        }
    },

    watch: {
        'row': {
            immediate: true, // vue首次赋值不触发watch的解决方法
            handler: function(nval){
                if (this.isModule) {
                    // this.temp = Object.assign({}, this.row) // copy obj
                    if (this.isNull(nval)) {return}
                    if (this.isNull(nval.id)) {return}
                    this.getList(nval.id)
                }
            }
        }
    },

    methods: {
        getList(_id) {
            this.resetTemp()
            fetchList({id:_id}).then(result => {
                if (!result.success) {
                    this.notify(result)
                    return
                }
                this.temp = result.map.rows[0]
            })
        },
        // 给外部调用，清空form
        resetTemp() {
            this.temp = {
                tmptUserType: '',
                tmptAuthPosition: '',
                tmptAuthDeptPostId: '',
                ctcRegionId: '',
                clientId: '',
                positionShow: '',
                contactType: '',
                policceNumber: '',
                headPic: '',
                lawEqpNo: '',
                loginname: '',
                name: '',
                idcardno: '',
                email: '',
                jobNumber: '',
                phone: '',
                telephone: '',
                sex: '',
                tmptAuthDeptId: '',
                deleteflag: '',
                id: undefined
            }
        },
        // 给外部调用，设置默认值，请根据实际情况修改id值
        defaultTemp() {
            this.temp = {
                deleteflag: 0 //设置默认值
            }
        },
        // 树表： 拿当前节点ID作为父节点ID，建立树关系
        setParentNodeId(id) {
            // this.temp.tmptAuthUserId = id
            this.temp.parentId = id
        },
        // 给外部调用，插入记录
        createData() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    const param = Object.assign({}, this.temp)
                    createApi(param).then((r) => {
                        this.notify(r)
                        if (r.success) {
                            this.resetTemp()
                            // 从父组件调用此方法，进行回调下
                            if (this.isModule) {
                                this.$emit('createResult')
                            }
                        }
                    })
                }
            })
        },
        // 给外部调用，修改记录
        updateData() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    // columnsTag.column4Add
                    const param = { id:this.temp.id }
                    param.tmptUserType = this.temp.tmptUserType
                    param.tmptAuthPosition = this.temp.tmptAuthPosition
                    param.tmptAuthDeptPostId = this.temp.tmptAuthDeptPostId
                    param.ctcRegionId = this.temp.ctcRegionId
                    param.clientId = this.temp.clientId
                    param.positionShow = this.temp.positionShow
                    param.contactType = this.temp.contactType
                    param.policceNumber = this.temp.policceNumber
                    param.headPic = this.temp.headPic
                    param.lawEqpNo = this.temp.lawEqpNo
                    param.loginname = this.temp.loginname
                    param.name = this.temp.name
                    param.idcardno = this.temp.idcardno
                    param.email = this.temp.email
                    param.jobNumber = this.temp.jobNumber
                    param.phone = this.temp.phone
                    param.telephone = this.temp.telephone
                    param.sex = this.temp.sex
                    param.tmptAuthDeptId = this.temp.tmptAuthDeptId
                    param.deleteflag = this.temp.deleteflag
                    updateApi(param).then((r) => {
                        this.notify(r)
                        if (r.success) {
                            this.resetTemp()
                            // 从父组件调用此方法，进行回调下
                            if (this.isModule) {
                                this.$emit('updateResult')
                            }
                        }
                    })
                }
            })
        },
        // 给外部调用，清除校验
        clearValidate() {
            this.$refs['dataForm'].clearValidate()
        }
    }

}
</script>
<style>

</style>
